//package com.youedata.util;
//
//import cn.stylefeng.roses.core.datascope.DataScope;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.google.common.collect.Lists;
//import com.youedata.modular.entity.TeacherUserRel;
//import com.youedata.modular.mapper.TeacherUserRelMapper;
//import com.youedata.sys.core.util.UserHolder;
//import com.youedata.sys.modular.system.entity.Dept;
//import com.youedata.sys.modular.system.mapper.DeptMapper;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//import java.util.stream.Collectors;
//
//@Component
//@Slf4j
//public class DataScopeKit {
//
//    @Autowired
//    private DeptMapper deptMapper;
//
//    @Autowired
//    private TeacherUserRelMapper teacherUserRelMapper;
//
//    @Autowired
//    private TeacherInfoMapper teacherInfoMapper;
//
//    public static DataScope init() {
//        DataScope dataScope = new DataScope();
//        dataScope.setScopeName("dept_id");
//        dataScope.setDeptIds(UserHolder.getDeptIds());
//        return dataScope;
//    }
//
//    /**
//     * 非超级管理员按区域查看班级信息
//     *
//     * @return
//     */
//    public DataScope getAreaClassDataScope() {
//        Long deptId = UserHolder.getSysUser().getDeptId();
//        String pids = deptMapper.selectById(deptId).getPids();
//        String[] pIdArr = pids.split(",");
//        List<Long> pIds = Lists.newArrayList();
//        for (String pid : pIdArr) {
//            String pId = pid.replaceAll("\\[", "").replaceAll("]", "").trim();
//            pIds.add(Long.valueOf(pId));
//        }
//        List<Dept> depts = deptMapper.selectList(new QueryWrapper<Dept>().eq("pids", pids));
//        List<Long> deptIds = depts.stream().map(Dept::getDeptId).collect(Collectors.toList());
//        pIds.addAll(deptIds);
//
//        DataScope dataScope = new DataScope();
//        dataScope.setScopeName("dept_id");
//        dataScope.setDeptIds(pIds);
//
//        return dataScope;
//    }
//
//    /**
//     * 获取自己班级数据范围
//     *
//     * @return
//     */
//    public DataScope getMyClassDataScope() {
//        List<Long> classIds = Lists.newArrayList();
//        List<TeacherUserRel> teacherUserRels = teacherUserRelMapper.selectList(new QueryWrapper<TeacherUserRel>().eq("user_id", UserHolder.getUserId()));
//        if (ToolUtil.isNotEmpty(teacherUserRels)) {
//            List<Long> teacherIds = teacherUserRels.stream().map(TeacherUserRel::getTeacherId).collect(Collectors.toList());
//            List<TeacherInfo> teacherInfos = teacherInfoMapper.selectList(new QueryWrapper<TeacherInfo>().in("id", teacherIds));
//            if (ToolUtil.isNotEmpty(teacherInfos)) {
//                classIds = teacherInfos.stream().map(TeacherInfo::getClassId).collect(Collectors.toList());
//            }
//        }
//        DataScope dataScope = new DataScope();
//        dataScope.setScopeName("class_id");
//        dataScope.setDeptIds(classIds);
//        return dataScope;
//    }
//
//}
